// using 2 kinds of color to fill polygon;
// using line with 2 kinds of color to draw polygon.
// ref. p.91

#include <gl/freeglut.h>

GLuint winWidth = 600, winHeight = 400;

static void init(void)
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0, winWidth, 0, winHeight);
}

static void display(void)
{
	// 6 points of a hexagon
	int p1[] = { 0, 100 };
	int p2[] = { 50, 13 };
	int p3[] = { 150, 13 };
	int p4[] = { 200, 100 };
	int p5[] = { 150, 187 };
	int p6[] = { 50, 187 };

	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0.0, 1.0, 0.0);
	/* Invoke polygon-generating routine */
	glBegin(GL_POLYGON);
	glVertex2iv(p1);
	glVertex2iv(p2);
	glVertex2iv(p3);
	glVertex2iv(p4);
	glVertex2iv(p5);
	glVertex2iv(p6);
	glEnd();

	glColor3f(1.0, 0.0, 0.0);
	glPolygonMode(GL_FRONT, GL_LINE);
	/* Invoke polygon-generating routine again */
	glBegin(GL_POLYGON);
	glVertex2iv(p1);
	glVertex2iv(p2);
	glVertex2iv(p3);
	glVertex2iv(p4);
	glVertex2iv(p5);
	glVertex2iv(p6);
	glEnd();

	glFlush();
}

static void reshape(int w, int h)
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0, w, 0, h);
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowPosition(10, 50);
	glutInitWindowSize(winWidth, winHeight);
	glutCreateWindow("Polygon Color");

	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	glutMainLoop();
	return 0;
}